package com.hqyj.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Autor 伍军
 * @Date 2022/10/17 15:04
 * @Version 1.0
 **/
//@Configuration
public class MqConfig {

    /*---------------消息转换配置-----*/
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }


    //创建一个消息队列
    @Bean
    public Queue helloQueue01(){
        //Queue(队列名称，消息是否持久化)
        // 队列名称 要和 方法名一致
        return new Queue("helloQueue01",true);
    }

    //创建第二个消息队列
    @Bean
    public Queue helloQueue02(){
        //Queue(队列名称，消息是否持久化)
        // 队列名称 要和 方法名一致
        return new Queue("helloQueue02",true);
    }

    //创建一个交换机
    @Bean
    public DirectExchange helloExchange(){
        // 交换机名称 要和 方法名一致
        return new DirectExchange("helloExchange");
    }

    //把helloQueue01消息队列和交换机绑定
    @Bean
    public Binding bingQueueAndExange(){
        //helloRoute01 访问这个helloQueue01队列的路由地址
        return BindingBuilder.bind(helloQueue01()).to(helloExchange()).with("helloRoute01");
    }
    //把helloQueue02消息队列和交换机绑定
    @Bean
    public Binding bingQueueAndExange01(){
        //helloRoute01 访问这个helloQueue01队列的路由地址
        return BindingBuilder.bind(helloQueue02()).to(helloExchange()).with("helloRoute02");
    }





}
